<template>
    <div style="padding: 10px;">
        <!--        <el-form :model="queryParams" ref="queryForm" class="queryForm" :inline="true" v-show="showSearch"-->
        <!--                 @submit.native.prevent>-->
        <!--            <el-form-item label="名称" desc="名称" prop="name">-->
        <!--                <el-input v-model.trim="queryParams.name" placeholder="名称" clearable size="small" style="width:120px;"-->
        <!--                          @keyup.enter.native="handleQuery" />-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="标识码" desc="标识码" prop="code">-->
        <!--                <el-input v-model.trim="queryParams.code" placeholder="标识码" clearable size="small" style="width:120px;"-->
        <!--                          @keyup.enter.native="handleQuery" />-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="所属字典ID[关系=SysDictionary]" desc="所属字典ID[关系=SysDictionary]" prop="dicId">-->
        <!--                <el-input v-model.trim="queryParams.dicId" placeholder="所属字典ID[关系=SysDictionary]" clearable size="small"-->
        <!--                          style="width:120px;" @keyup.enter.native="handleQuery" />-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="状态" desc="状态 1 使用中  5停用" prop="state">-->
        <!--                <dic-select v-model="queryParams.state" :code="dicInner.sys_dictionary_value_state"-->
        <!--                            placeholder="状态 1 使用中  5停用" clearable size="small" style="width:120px;"-->
        <!--                            @keyup.enter.native="handleQuery" />-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="排序号" desc="排序号" prop="orderNum">-->
        <!--                <el-input v-model.trim="queryParams.orderNum" placeholder="排序号" clearable size="small"-->
        <!--                          style="width:120px;" @keyup.enter.native="handleQuery" />-->
        <!--            </el-form-item>-->
        <!--            <el-form-item>-->
        <!--                <el-button type="primary" icon="el-icon-search" size="mini" @submit.native.prevent @click="handleQuery">-->
        <!--                    搜索-->
        <!--                </el-button>-->
        <!--                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
        <!--            </el-form-item>-->
        <!--        </el-form>-->
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5" class="buttonsRow">
                <el-button type="primary" size="small" plain @click="()=>triggerModify()">新增</el-button>
            </el-col>
            <right-toolbar @layout="(_obj)=>columnsHidden=_obj" :showSearch.sync="showSearch"
                           @queryTable="getInfoList"></right-toolbar>
        </el-row>
        <section class="tablecontainer">
            <el-table border ref="multipleTable" :data="dataList" size="mini" class="tabletop" tooltip-effect="dark"
                      style="width: 100%" @selection-change="rows=>{         selectRows=rows      }"
                      @row-click="row=>{          tableRowClickOnece(row,'multipleTable')      }"
                      :row-class-name="tableRowClassName">
                <el-table-column type="selection" width="40" align="center"></el-table-column>
                <el-table-column label="操作" width="55" align="center">
                    <template slot-scope="scope">
                        <el-popover placement="top-start" title="操作" width="222" trigger="hover">
                            <div>
                                <el-button size="mini" type="text" icon="el-icon-edit"
                                           @click="()=>triggerModify(scope.row)"> 修改
                                </el-button>
                                <el-button size="mini" type="text" icon="el-icon-notebook-1"
                                           @click="()=>openLog(scope.row)">变更日志
                                </el-button>
                                <el-button size="mini" type="text" icon="el-icon-delete"
                                           @click="()=>handleDelete(scope.row)">删除
                                </el-button>
                            </div>
                            <el-button slot="reference" type="text">操作</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
                <el-table-column v-if="!columnsHidden['name']" label="名称" prop="name" min-width="120px;">
                    <template slot-scope="scope">
                        <div> {{scope.row.name}}</div>
                    </template>
                </el-table-column>
                <el-table-column v-if="!columnsHidden['code']" label="标识码" prop="code" min-width="120px;">
                    <template slot-scope="scope">
                        <div> {{scope.row.code}}</div>
                    </template>
                </el-table-column>
                <!-- <el-table-column v-if="!columnsHidden['dicId']" label="所属字典ID[关系=SysDictionary]" prop="dicId"
                                  min-width="120px;">
                     <template slot-scope="scope">
                         <div> {{scope.row.dicId}}</div>
                     </template>
                 </el-table-column>-->
                <!--<el-table-column v-if="!columnsHidden['state']" label="状态" prop="state" min-width="120px;">
                    <template slot-scope="scope">
                        <dic-tag :code="dicInner.sys_dictionary_value_state" v-model="scope.row.state"></dic-tag>
                    </template>
                </el-table-column>-->
                <el-table-column v-if="!columnsHidden['orderNum']" label="排序号" prop="orderNum" min-width="120px;">
                    <template slot-scope="scope">
                        <div> {{scope.row.orderNum}}</div>
                    </template>
                </el-table-column>
                <!--  <el-table-column label="添加时间/人" prop="add_time/add_user" v-if="!columnsHidden['add_time/add_user']">
                      <template slot-scope="scope">
                          <span>{{scope.row.addTime|dateFormatYYYYMMDD}}/{{scope.row.addUser}}</span></template>
                  </el-table-column>
                  <el-table-column label="更新时间/人" prop="lastEditTime/editUser"
                                   v-if="!columnsHidden['lastEditTime/editUser']">
                      <template slot-scope="scope"><span>{{scope.row.lastEditTime|dateFormatYYYYMMDD}}/{{scope.row.editUser}}</span>
                      </template>
                  </el-table-column>-->
            </el-table>
            <el-pagination :background="true" style="padding: 20px;" :current-page.sync="queryParams.pageNum"
                           :page-size="queryParams.pageSize" layout="prev, pager, next" :total="total"
                           @size-change="(pageSize)=>{$data.queryParams.pageSize=pageSize;dataList=[];getInfoList();}"
                           @current-change="(pageNum)=>{$data.queryParams.pageNum=pageNum;dataList=[];getInfoList();}"></el-pagination>
        </section>
    </div>
</template>
<script>  import { formData, formMethod, PageData } from '@/utils/formcommon';
import { getUrlParam, dateFormatYYYYMMDD } from '@/utils/index';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import * as  api from '@/apis/sysDictionaryValue.api.js';

const dicInner = {
  '___sys_dictionary_value_id': '主键ID',
  'sys_dictionary_value_id': 'sys_dictionary_value_id',
  '___sys_dictionary_value_name': '名称',
  'sys_dictionary_value_name': 'sys_dictionary_value_name',
  '___sys_dictionary_value_code': '标识码',
  'sys_dictionary_value_code': 'sys_dictionary_value_code',
  '___sys_dictionary_value_dicId': '所属字典ID[关系=SysDictionary]',
  'sys_dictionary_value_dicId': 'sys_dictionary_value_dicId',
  '___sys_dictionary_value_state': '状态 1 使用中  5停用',
  'sys_dictionary_value_state': 'sys_dictionary_value_state',
  '___sys_dictionary_value_orderNum': '排序号',
  'sys_dictionary_value_orderNum': 'sys_dictionary_value_orderNum',
  '___sys_dictionary_value_remarks': '备注',
  'sys_dictionary_value_remarks': 'sys_dictionary_value_remarks',
  '___sys_dictionary_value_tenantType': '租户类型 1应用管理者2应用消息者',
  'sys_dictionary_value_tenantType': 'sys_dictionary_value_tenantType',
  '___sys_dictionary_value_tenantId': '租户ID',
  'sys_dictionary_value_tenantId': 'sys_dictionary_value_tenantId',
  '___sys_dictionary_value_delState': '有效状态[数据字典=del_state] 1有效  5删除',
  'sys_dictionary_value_delState': 'sys_dictionary_value_delState',
  '___sys_dictionary_value_addUser': '添加人',
  'sys_dictionary_value_addUser': 'sys_dictionary_value_addUser',
  '___sys_dictionary_value_addUserId': '添加人ID',
  'sys_dictionary_value_addUserId': 'sys_dictionary_value_addUserId',
  '___sys_dictionary_value_addTime': '添加时间',
  'sys_dictionary_value_addTime': 'sys_dictionary_value_addTime',
  '___sys_dictionary_value_editUser': '最近更新人',
  'sys_dictionary_value_editUser': 'sys_dictionary_value_editUser',
  '___sys_dictionary_value_editUserId': '最近更新人ID',
  'sys_dictionary_value_editUserId': 'sys_dictionary_value_editUserId',
  '___sys_dictionary_value_lastEditTime': '最近更新时间',
  'sys_dictionary_value_lastEditTime': 'sys_dictionary_value_lastEditTime',
  '___sys_dictionary_value_serverNumber': '服务器编号ID',
  'sys_dictionary_value_serverNumber': 'sys_dictionary_value_serverNumber',
};
export default {
  name: 'sysDictionaryValuelist',
  data() {
    return {
      api: api,
      dicInner, ...formData,
      queryParams: {
        name: '',
        searchKey: '',
        'id': '',
        'name': '',
        'code': '',
        'dicId': '',
        'state': '',
        'orderNum': '',
        'remarks': '',
        'tenantType': '',
        'tenantId': '',
        'delState': '',
        'addUser': '',
        'addUserId': '',
        'addTime': '',
        'editUser': '',
        'editUserId': '',
        'lastEditTime': '',
        'serverNumber': '', ...PageData,
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
    RightToolbar: () => import('@/components/RightToolbar/index.vue'),
  },
  mounted() {
    /*if (this.$props['immediate']) {
      this.getInfoList();
    }*/
  },
  filters: { dateFormatYYYYMMDD: dateFormatYYYYMMDD },
  computed: {},
  watch: {},
  props: {
    immediate: {
      type: [Boolean], default() {
        return true;
      },
    },
  },
  methods: {
    ...formMethod,
    /**     * @description:
     * * @params _data.dataList
     * @params _data.dicId
     *  * @return     */
    initByDialog(_data) {
      this.queryParams.dicId = _data && _data.dicId;
      this.queryParams.pageNum = 1;
      this.getInfoList();
    },
    tableRowClickOnece(row, tableRef, options) {
      var table = this.$refs[tableRef];
      if (options && options.canSelect) {
        var istrue = options.canSelect(row);
        if (!istrue) {
          table && table.toggleRowSelection(row, false);
        }
      }
      table && table.clearSelection();
      table && table.toggleRowSelection(row);
    },
    async triggerModify(row) {
      var self = this;
      var result = await FormDialog({
        width: '555px', title: row && row.id ? '编辑字典' : '新增字典', data() {
          return {
            ...row,
            dicId: self.queryParams.dicId,
          };
        }, components: { modify: () => import('@/views/dic/values/modiy.vue') },
      });
      if (!(result && result.success)) {
        return result;
      }
      this.getInfoList();
    },
  },
};</script>
